<script type="text/ecmascript-6">

//  import { Navbar } from 'vmc';
//  import { cache as Cache, cache_keys } from '../../drivers/utils';

//  import { queryChubDetail, queryChubFavoState, submitChutFavo } from '../../datas/actions/chub';
//  import { getChubDetail } from '../../datas/getters/chub';
    import {  Cache, cache_keys } from '../../utils/util';
    import { mapGetters } from 'vuex'
  export default {
    name:"chub_detail",
    components: {
//      Navbar
    },
    data() {
      return {
        shareTip: false,
        title: '',
        isLogin: false,
        isFavo: false,
        id: this.$route.params.id,
      }
    },
    methods: {
      jump(page, id) {
          window.location.href="http://m.dev.tnf.ibrand.cc/#!/chub/"+page+"/"+id;
//        this.$router.forward({ name: page, params: {id: id} });
      },
      go(page,id){
         this.$router.push({name:page,params:{id:id}});
      },
      favo() {
        if( this.isLogin ){
          var action =  Number(!this.isFavo);
            this.$store.dispatch('submitChutFavo',{id:this.id,action:action});
        }else{
//          window.location.href="http://m.dev.tnf.ibrand.cc/#!/user/login/quick";
          this.$router.push({ name: 'login-quick', query: { source: this.$route.path } });
//          console.log(1);
        }
      },
      setTitle(title){
          this.title=title;
      },
      completeQueryFavo(res) {
        this.isFavo = !!res;
      },
      completeSubmitFavo(res) {
        this.isFavo = !!res;
        if(res){
      let remove=this.$Message.show({text:"收藏成功",type:"loading"}); //返回当前message实例,可手动删除
          setTimeout(()=>{
            remove();
          },3000)
//          this.$Modal.info({title:'消息提示',body:'收藏成功'});
        }else{
          let remove=this.$Message.show({text:"取消收藏成功",type:"loading"}); //返回当前message实例,可手动删除
          setTimeout(()=>{
            remove();
          },3000)
        }
      }
    },
    created(){
      EventBus.$on("set-title",this.setTitle);
      EventBus.$on("complete-submitFavo",this.completeSubmitFavo);
      EventBus.$on("complete-queryFavo",this.completeQueryFavo);
    },
    mounted(){
      this.$Indicator.blade();
      this.$store.dispatch('queryChubDetail', this.id);

//      this.isLogin = Cache.get('user_token');
//      console.log(Cache.get('user_token'));
      this.isLogin = !!Cache.get(cache_keys.token);
      if(this.isLogin) this.$store.dispatch('queryChubFavoState',this.id);
    },
//     events:{
//        setTitle(title){
//            this.title=title;
//        }
//     },
//    ready() {
////      this.$Loading();
////      this.queryChubDetail(this.id);
////
////      this.isLogin = !!Cache.get(cache_keys.token);
////      if( this.isLogin ) this.queryChubFavoState(this.id);
//    },
    computed:{
        favoStatus(){
          if(this.isFavo){
            return 1;
          }else{
            return 0;
          }
        },
      isFavoState(){
        if(this.isFavo){
          return "已收藏";
        }else{
          return "收藏";
        }
      },
      chubDetail:{
        get(){
            return this.$store.getters.getChubDetail
        }
      }
    },
    beforeDestroy(){
      EventBus.$off("set-title");
      EventBus.$off("complete-submitFavo");
      EventBus.$off("complete-queryFavo");
    },

  }
</script>
